package com.epoint.mobileoa.ui.main;

import java.util.List;

import org.taptwo.android.widget.viewflow.example.MainViewCircleAdapter;

import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.GVIcon;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.protocol.MainIconDataSource;

/**
 * MobileOA3.0
 * @author liyc
 * @time 2013-1-4 下午4:49:41 
 */
public class MainViewNew extends SuperView implements MainIconDataSource{
	List<GVIcon> list;
	GridView gv;
	LinearLayout lltop;
	ImageView ivbg;
	MainViewGvAdapter adapter;
	@Override
	public void initControls() {
		// TODO 自动生成的方法存根
		ivbg = (ImageView) findViewById(R.id.ivbg);
		hideTopBar();
		list = iconDataSource();
		lltop = (LinearLayout) findViewById(R.id.lltop);
		gv = (GridView) findViewById(R.id.gv);
		adapter = new MainViewGvAdapter(this, list);
		gv.setAdapter(adapter);
		gv.setOnItemClickListener(this);
		//欢迎
		MainView.showWelcome(this);
		//是否开通提示
		MainView.Tip(this);
		//检测更新
		MainView.ShowUpdate(this);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO 自动生成的方法存根
		super.onItemClick(parent, view, position, id);
		startActivity(list.get(position).intent);
	}
	
	@Override
	public void KEYCODE_BACK() {
		MainView.quitApp(this);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		//设置登陆页背景主题
		if(getBackgroundStr().equals("background")){
			ivbg.setImageResource(R.drawable.background);
			lltop.setBackgroundResource(R.drawable.toolbar_bg);
		}
		else{
			ivbg.setImageResource(R.drawable.mainbg);
			lltop.setBackgroundResource(R.drawable.top_back_image);
		}
		adapter.notifyDataSetChanged();
	}

	@Override
	@Deprecated
	public void refresh(Object... param) throws Exception {
		// TODO 自动生成的方法存根

	}

	@Override
	public void refreshForNewTask(int TaskId, Object... param) {
		// TODO 自动生成的方法存根

	}

	@Override
	public int getLayoutInt() {
		// TODO 自动生成的方法存根
		return R.layout.mainviewnew;
	}

	@Override
	public List<GVIcon> iconDataSource() {
		return new MainViewIconInstance().iconDataSource(this);
	}


}
